package 树;

import 抽象数据类型.TreeNode;

/**
 * @author: yangwk
 * @date: 2023/4/4
 * @description:
 **/
public class 树的深度 {
    //树的深度

    public static int heightOfTree(TreeNode root) {
        int leftHeight, rightHeight;
        if (root == null) {
            return 0;
        }
        leftHeight = heightOfTree(root.left) + 1;
        rightHeight = heightOfTree(root.right) + 1;
        return Math.max(leftHeight, rightHeight);
    }
}
